Skip to content

test: add config and rate limit coverage - #685

Merged
rafaelscosta merged 1 commit into
mainfrom
devops/test-config-rate-limit-coverage-20260507
May 8, 2026
Merged

test: add config and rate limit coverage#685
rafaelscosta merged 1 commit into
mainfrom
devops/test-config-rate-limit-coverage-20260507

Conversation

@rafaelscosta

@rafaelscosta rafaelscosta commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds focused unit coverage for RateLimitManager, including retry behavior, backoff, metrics, event logging, wrapper helper, and singleton manager.
  • Adds config coverage for env-interpolator, including string interpolation, nested object/array handling, missing-var warnings, lint detection, and regex behavior.
  • Adds config coverage for merge-utils, including plain object detection, deep merge semantics, append arrays, null deletion, immutability, and mergeAll ordering.

Supersedes #598 and #609 with a fresh test-only branch based on current main.

Validation

  • npm test -- tests/core/config/env-interpolator.test.js tests/core/config/merge-utils.test.js tests/core/execution/rate-limit-manager.test.js --runInBand
  • npm run lint -- --quiet --ignore-pattern .aiox-core/data/entity-registry.yaml
  • npm run typecheck
  • npm run validate:manifest
  • git diff --check

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for environment variable interpolation: string/default rules, nested structures, warning collection, regex behavior, and env setup/teardown per test.
    • Added thorough tests for deep-merge utilities: plain-object detection, merge/array semantics, deletion behavior, multi-layer merging, and non-mutation guarantees.
    • Added extensive tests for rate-limit manager: error detection, delay/retry flows, metrics/events, wrapper behavior, and singleton guarantees.

@vercel

vercel Bot commented May 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aiox-core Ready Ready Preview, Comment May 8, 2026 0:49am

Request Review

@coderabbitai

coderabbitai Bot commented May 8, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds three Jest test suites: env-interpolator (string/object interpolation, pattern linting, ENV_VAR_PATTERN), merge-utils (isPlainObject, deepMerge, mergeAll), and rate-limit-manager (constructor, error detection, delay logic, retries, metrics, wrapper, singleton). No production code changed.

Changes

Environment Interpolation Test Suite

Layer / File(s) Summary
String Interpolation
tests/core/config/env-interpolator.test.js
Tests interpolateString for ${VAR} resolution, ${VAR:-default} handling, missing-variable warnings, and multi-variable interpolation.
Object and Array Traversal
tests/core/config/env-interpolator.test.js
Tests interpolateEnvVars for deep nested interpolation, input non-mutation, and primitive value preservation.
Pattern Detection
tests/core/config/env-interpolator.test.js
Tests lintEnvPatterns for placeholder discovery in nested structures and path reporting.
Regex Export
tests/core/config/env-interpolator.test.js
Tests ENV_VAR_PATTERN global regex and capture group functionality.

Merge Utilities Test Suite

Layer / File(s) Summary
Object Type Detection
tests/core/config/merge-utils.test.js
Tests isPlainObject for plain objects, Object.create(null), and rejection of arrays, null/undefined, and built-in types.
Deep Merge Function
tests/core/config/merge-utils.test.js
Tests deepMerge for scalar last-wins, nested recursion, +append array concatenation, null-key deletion, and non-mutation.
Multi-Layer Merge
tests/core/config/merge-utils.test.js
Tests mergeAll for ordered composition, null/undefined skipping, and shallow copy behavior.

Rate Limit Manager Test Suite

Layer / File(s) Summary
Constructor Initialization
tests/core/execution/rate-limit-manager.test.js
Tests RateLimitManager constructor with default and custom configuration, zero-initialized metrics, and EventEmitter compatibility.
Error Detection
tests/core/execution/rate-limit-manager.test.js
Tests isRateLimitError for detection via HTTP status codes, message patterns, and error codes.
Delay Calculation
tests/core/execution/rate-limit-manager.test.js
Tests calculateDelay with retryAfter precedence, Retry-After parsing, exponential backoff with jitter, and maxDelay capping.
Retry Execution
tests/core/execution/rate-limit-manager.test.js
Tests executeWithRetry for first-attempt success, retry on rate-limit errors, max-retry exhaustion, and event emission.
Metrics and Events
tests/core/execution/rate-limit-manager.test.js
Tests metrics calculation (average wait time, success rate), event log capping, recent-event slicing, metrics reset, and status formatting.
Wrapper and Singleton
tests/core/execution/rate-limit-manager.test.js
Tests withRateLimit wrapper retry behavior and getGlobalManager singleton behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • Pedrovaleriolopez
  • oalanicolas
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: add config and rate limit coverage' accurately and concisely summarizes the main changes—adding comprehensive test coverage for config utilities and rate limiting functionality across three test files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devops/test-config-rate-limit-coverage-20260507

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added area: agents Agent system related area: workflows Workflow system related squad mcp type: test Test coverage and quality area: core Core framework (.aios-core/core/) area: installer Installer and setup (packages/installer/) area: synapse SYNAPSE context engine area: cli CLI tools (bin/, packages/aios-pro-cli/) area: pro Pro features (pro/) area: health-check Health check system area: docs Documentation (docs/) area: devops CI/CD, GitHub Actions (.github/) labels May 8, 2026
@rafaelscosta
rafaelscosta force-pushed the devops/test-config-rate-limit-coverage-20260507 branch from 4159e93 to 32e0dd7 Compare May 8, 2026 00:42
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

📊 Coverage Report

Coverage report not available

📈 Full coverage report available in Codecov


Generated by PR Automation (Story 6.1)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/core/config/env-interpolator.test.js`:
- Around line 12-17: The test is importing interpolateString,
interpolateEnvVars, lintEnvPatterns, and ENV_VAR_PATTERN via a relative require;
change that require to use the project's absolute import path (e.g., the
package/module root import that maps to .aiox-core/core/config/env-interpolator)
so the line requiring these symbols uses the absolute module name instead of
'../../../.aiox-core/...'; keep the same destructured symbols
(interpolateString, interpolateEnvVars, lintEnvPatterns, ENV_VAR_PATTERN) and
update only the module specifier to the project's approved absolute import.

In `@tests/core/config/merge-utils.test.js`:
- Line 12: The test imports merge utilities using a relative path; update the
require to use the project's absolute module import instead so it follows the
"absolute imports" rule: replace the relative
require('../../../.aiox-core/core/config/merge-utils') in
tests/core/config/merge-utils.test.js with the absolute module import for the
same module and keep the imported symbols (deepMerge, mergeAll, isPlainObject)
unchanged so the tests still reference those functions.

In `@tests/core/execution/rate-limit-manager.test.js`:
- Line 13: Replace the relative require of the RateLimitManager module with an
absolute import: instead of const RateLimitManager =
require('../../../.aiox-core/core/execution/rate-limit-manager'); use the
project-root absolute path import (for example
require('.aiox-core/core/execution/rate-limit-manager') or the project's
configured absolute alias) so the test imports the same module via an absolute
path and satisfies the repository lint rule; adjust to use import syntax if the
codebase prefers ES modules.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 719cb66e-eecc-4f53-99e6-1c512b9eec66

📥 Commits

Reviewing files that changed from the base of the PR and between 11c130d and 4159e93.

📒 Files selected for processing (3)
  • tests/core/config/env-interpolator.test.js
  • tests/core/config/merge-utils.test.js
  • tests/core/execution/rate-limit-manager.test.js

Comment thread tests/core/config/env-interpolator.test.js Outdated
Comment thread tests/core/config/merge-utils.test.js Outdated
Comment thread tests/core/execution/rate-limit-manager.test.js Outdated
@rafaelscosta
rafaelscosta force-pushed the devops/test-config-rate-limit-coverage-20260507 branch from 32e0dd7 to 195fb96 Compare May 8, 2026 00:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
tests/core/config/env-interpolator.test.js (1)

14-21: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Relative import — use an absolute module specifier.

The path.resolve(__dirname, ...) + path.join(...) construction is still a relative import in disguise and violates the project's coding standards.

As per coding guidelines, "Use absolute imports instead of relative imports in all code" for **/*.{js,jsx,ts,tsx} files.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/core/config/env-interpolator.test.js` around lines 14 - 21, The test
uses a relative-import workaround (path.resolve(__dirname, ...) +
path.join(...)) to require the module that exports interpolateString,
interpolateEnvVars, lintEnvPatterns, and ENV_VAR_PATTERN; replace that with a
single absolute module specifier require call (e.g.,
require('aiox-core/core/config/env-interpolator') or whatever the project’s
canonical absolute package path is) and keep the existing destructured imports
so the test imports interpolateString, interpolateEnvVars, lintEnvPatterns, and
ENV_VAR_PATTERN via the absolute require instead of constructing a filesystem
path.
🧹 Nitpick comments (2)
tests/core/config/env-interpolator.test.js (2)

204-219: ⚡ Quick win

ENV_VAR_PATTERN global lastIndex can leak across the preceding test runs.

The interpolateString and interpolateEnvVars suites invoke the production functions that internally consume ENV_VAR_PATTERN (a global regex). If the implementation ever exits a exec()-loop early (e.g., error path), lastIndex could be left non-zero. While the tests here correctly use new RegExp(ENV_VAR_PATTERN.source) for their own assertions — so these tests are safe — adding an explicit beforeEach reset prevents any future direct use of ENV_VAR_PATTERN in this block from being order-dependent.

♻️ Proposed safeguard
 describe('ENV_VAR_PATTERN', () => {
+  beforeEach(() => {
+    ENV_VAR_PATTERN.lastIndex = 0;
+  });
+
   it('deve ser uma regex global', () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/core/config/env-interpolator.test.js` around lines 204 - 219, Add a
beforeEach in this describe block that resets the global regex state to avoid
test-order flakiness: explicitly set ENV_VAR_PATTERN.lastIndex = 0 before each
test so that any prior exec() usage by interpolateString or interpolateEnvVars
cannot leak a non-zero lastIndex into these specs; reference the ENV_VAR_PATTERN
identifier and mention the related functions interpolateString and
interpolateEnvVars so maintainers know why the reset is needed.

28-36: ⚡ Quick win

process.env isolation should use afterEach, not afterAll.

Both describe blocks restore process.env only in afterAll. If a test throws unexpectedly (rather than an assertion failure), the remaining tests in that block still receive a reset env via beforeEach, but any parallelized or cross-describe side effects accumulate until the entire suite for that block finishes. Replacing afterAll with afterEach makes the cleanup symmetric with beforeEach and removes any ambiguity.

♻️ Proposed fix (applies to both describe blocks at lines 34–36 and 90–92)
-  afterAll(() => {
+  afterEach(() => {
     process.env = ORIGINAL_ENV;
   });

Also applies to: 84-92

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/core/config/env-interpolator.test.js` around lines 28 - 36, The test
restores process.env in an afterAll but the setup uses beforeEach, so switch the
teardown to afterEach to ensure isolation per-test; update the two occurrences
of afterAll (() => { process.env = ORIGINAL_ENV; }) to afterEach (() => {
process.env = ORIGINAL_ENV; }) in the env-interpolator.test.js file so the
beforeEach/afterEach pair correctly reset process.env for each test (apply to
both describe blocks that reference ORIGINAL_ENV, beforeEach, and afterAll).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@tests/core/config/env-interpolator.test.js`:
- Around line 14-21: The test uses a relative-import workaround
(path.resolve(__dirname, ...) + path.join(...)) to require the module that
exports interpolateString, interpolateEnvVars, lintEnvPatterns, and
ENV_VAR_PATTERN; replace that with a single absolute module specifier require
call (e.g., require('aiox-core/core/config/env-interpolator') or whatever the
project’s canonical absolute package path is) and keep the existing destructured
imports so the test imports interpolateString, interpolateEnvVars,
lintEnvPatterns, and ENV_VAR_PATTERN via the absolute require instead of
constructing a filesystem path.

---

Nitpick comments:
In `@tests/core/config/env-interpolator.test.js`:
- Around line 204-219: Add a beforeEach in this describe block that resets the
global regex state to avoid test-order flakiness: explicitly set
ENV_VAR_PATTERN.lastIndex = 0 before each test so that any prior exec() usage by
interpolateString or interpolateEnvVars cannot leak a non-zero lastIndex into
these specs; reference the ENV_VAR_PATTERN identifier and mention the related
functions interpolateString and interpolateEnvVars so maintainers know why the
reset is needed.
- Around line 28-36: The test restores process.env in an afterAll but the setup
uses beforeEach, so switch the teardown to afterEach to ensure isolation
per-test; update the two occurrences of afterAll (() => { process.env =
ORIGINAL_ENV; }) to afterEach (() => { process.env = ORIGINAL_ENV; }) in the
env-interpolator.test.js file so the beforeEach/afterEach pair correctly reset
process.env for each test (apply to both describe blocks that reference
ORIGINAL_ENV, beforeEach, and afterAll).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5b989d88-e0bd-411d-ad0c-cb5db36ff392

📥 Commits

Reviewing files that changed from the base of the PR and between 32e0dd7 and 195fb96.

📒 Files selected for processing (3)
  • tests/core/config/env-interpolator.test.js
  • tests/core/config/merge-utils.test.js
  • tests/core/execution/rate-limit-manager.test.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/core/execution/rate-limit-manager.test.js
  • tests/core/config/merge-utils.test.js

@rafaelscosta
rafaelscosta merged commit 1c3ba4e into main May 8, 2026
40 checks passed
@rafaelscosta
rafaelscosta deleted the devops/test-config-rate-limit-coverage-20260507 branch May 8, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agents Agent system related area: cli CLI tools (bin/, packages/aios-pro-cli/) area: core Core framework (.aios-core/core/) area: devops CI/CD, GitHub Actions (.github/) area: docs Documentation (docs/) area: health-check Health check system area: installer Installer and setup (packages/installer/) area: pro Pro features (pro/) area: synapse SYNAPSE context engine area: workflows Workflow system related mcp squad type: test Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant